#include "widget.h"
#include "ui_widget.h"
#include<QProgressBar>
#include<QDebug>
#include<QTimer>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    timer=new QTimer(this);
    connect(timer,&QTimer::timeout,this,&Widget::updateProgressBar);
    timer->start(100);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::updateProgressBar()
{
    int value=ui->progressBar->value();
//    ui->progressBar->setStyleSheet("QProgressBar::chunk {background-color:#42CF57;}");
    if(value>=100)
    {
        ui->progressBar->setStyleSheet("QProgressBar::chunk {background-color:#FF0000;}");
        timer->stop();
        ui->label->setText("下载完毕");
        return;
    }
    ui->progressBar->setValue(value+1);
}


void Widget::on_pushButton_clicked()
{
//    int value=ui->progressBar->value();
    ui->label->setText("加载已经暂停");
    timer->stop();
//    this->setEnabled(false);
//    ui->pushButton->setEnabled(false);
    ui->pushButton_2->setEnabled(true);
}

void Widget::on_pushButton_2_clicked()
{
    int value=ui->progressBar->value();
    ui->label->setText("已经继续");
    timer->start();
//    this->setEnabled();
    ui->progressBar->setValue(value+1);
}
